#!/bin/bash
# Author: fanyongfeng
# 0  1 * * * /bin/bash /root/script/gitlab_log_backup.sh &> /backup/gitlab_log_backup/backup.log

TODAY=$(date +%Y%m%d)
BACKUP_DIR="/backup/gitlab_log_backup"
BASE_DIR="/data/gitlab"
LOG_FILES="
${BASE_DIR}/log/gitlab-rails/application_json.log
${BASE_DIR}/log/gitlab-rails/audit_json.log
"

cd ${BACKUP_DIR}
for i in ${LOG_FILES}
do
    \cp -p $i ${BACKUP_DIR}/${log_name}.${TODAY} && gzip ${log_name}.${TODAY}
done

find ${BACKUP_DIR} -type f -mtime +180 -name "*.gz" | xargs -r -n 10 rm -f